import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const router = new VueRouter({
  routes: [
    // 一级容器
    //  布局组件，里面包含 头部(layout不含二级导航)和尾部
    {
      path: "/",
      component: () => import('../views/layout'),
      children: [
        // 里面是  音乐馆 我的音乐 等
        {
          // 音乐馆页面
          path: "/",
          component: () => import('../views/home/'),
          children: [
            {
              path: '/',
              component: () => import('../views/home/pages/index/index.vue'),
              meta: {
                title: "首页"
              }
            },
            {
              path: '/singer',
              component: () => import('../views/home/pages/singer'),
              meta: {
                title: "歌手"
              }
            },
            {
              path: '/album',
              component: () => import('../views/home/pages/album'),
              meta: {
                title: "数字专辑"
              }
            },
            {
              path: '/toplist',
              component: () => import('../views/home/pages/toplist'),
              meta: {
                title: "排行榜"
              }
            },
            {
              path: '/category',
              component: () => import('../views/home/pages/category'),
              meta: {
                title: "分类歌单"
              }
            },
            {
              path: '/mv',
              component: () => import('../views/home/pages/mv'),
              meta: {
                title: "MV"
              }
            },
            // 电台页面
            {
              path: "/radio",
              component: () => import('../views/home/pages/radio'),
              meta: {
                title: "电台"
              }
            },
            // 电台二级分类页面
            {
              path: "/radio/category/:id",
              component: () => import('../views/home/pages/radioCategory'),
              meta: {
              }
            },
            // xxxx 电台 详情页面
            {
              path: "/radioDetails/:id",
              component: () => import('../views/home/pages/radioCategoryDetails'),
              meta: {},
            },
            // 歌单详情页面
            {
              path: '/categoryDetails/:id',
              component: () => import('../views/home/pages/categoryDetails'),
              meta: {

              }
            },
            // MV 详情页面
            {
              path: '/mvDetails/:id',
              component: () => import('../views/home/pages/mvDetails'),
              meta: {

              }
            },
            // 歌曲详情页面
            {
              path: '/songDetails/:id',
              component: () => import('../views/home/pages/songDetails'),
              meta: {

              }
            },
            // 歌手详情
            {
              path: '/singerDetails/:id',
              component: () => import('../views/home/pages/singerDeatils'),
              meta: {

              }
            },
            // 数字专辑详情
            {
              path: '/albumDetails/:id',
              component: () => import('../views/home/pages/albumDetails'),
              meta: {

              }
            },
            // xxxx 用户 详情 
            {
              path: "/userDetails/:uid",
              component: () => import('../views/home/pages/userDetails/index.vue'),
              meta: {
              }
            },

          ]
        },
        // 我的音乐界面
        {
          path: "/mymusic",
          component: () => import("../views/mymusic"),
        },
        {
          path: "/login/:path?",
          component: () => import('../views/login'),
          meta: {
          }
        },
        {
          path: "/register/:path?",
          component: () => import('../views/register'),
          meta: {
          }
        },
        {
          path: "/search",
          component: () => import('../views/search'),
          meta: {}
        },

      ]
    },
    // 歌曲播放页面
    {
      path: "/player/:id?",
      component: () => import("../views/player")
    },
    // 电台播放页面
    {
      path: "/radioPlayer/:mainTrackId/:id",
      component: () => import('../views/radioPlayer')
    },


    // 404
  ]
})

/* 
解决: 在某个页面下点击，某个东西还是跳转到这个路由页面，只是 动态路由的参数不一样 导致报错
报错信息: Avoided redundant navigation to current location: "/singerDetails/29392693".
*/

const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

// 权限

export default router


// { path: '/', redirect: '/home' },
// {
//   path: '/home',
//     component: () => import('../views/home/index.vue'),
//       redirect: '/home/index',
//         children: [
//           {
//             path: 'index',
//             component: () => import('../views/home/pages/index/index.vue'),
//             meta: {
//               title: "首页"
//             }
//           },
//           {
//             path: 'singer',
//             component: () => import('../views/home/pages/singer'),
//             meta: {
//               title: "歌手"
//             }
//           },
//           {
//             path: 'album',
//             component: () => import('../views/home/pages/album'),
//             meta: {
//               title: "新碟上架"
//             }
//           },
//           {
//             path: 'toplist',
//             component: () => import('../views/home/pages/toplist'),
//             meta: {
//               title: "排行榜"
//             }
//           },
//           {
//             path: 'category',
//             component: () => import('../views/home/pages/category'),
//             meta: {
//               title: "分类歌单"
//             }
//           },
//           {
//             path: 'mv',
//             component: () => import('../views/home/pages/mv'),
//             meta: {
//               title: "MV"
//             }
//           },
//         ]
// },
// {
//   path: "/mymusic",
//     component: () => import("../views/mymusic"),

//     },
// {
//   path: "/player",
//     component: () => import("../views/player")
// }